import mysql from 'mysql'

const testDb = mysql.createPool({
  connectionLimit: 10,
  host: '120.25.144.98',
  user: 'root',
  password: '716673',
  database: 'test'
})

const query = (pool, sql, values) => {
  return new Promise((resolve, reject) => {
    pool.getConnection((err, connection) => {
      if (err) {
        resolve(err)
      } else {
        connection.query(sql, values, (err, rows) => {
          if (err) {
            reject(err)
          } else {
            resolve(rows)
          }
          connection.release()
        })
      }
    })
  })
}

export {
  testDb,
  query
}
